package org.dregs.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Maps;
import org.dregs.service.IndexService;
import org.dregs.utils.BuildMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static org.dregs.utils.BuildMap.*;
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private HttpServletRequest request;

    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private IndexService indexService;

    private Logger log = LoggerFactory.getLogger(IndexController.class);

    @GetMapping("/out/versionCompare/{md5}")
    public
    Map<String,Object>
    versionCompare(@PathVariable("md5") String md5) {
        return indexService.versionCompare(md5);
    }

    @GetMapping("/getAllInfo")
    public
    Map<String,Object>
    getAllInfo(){
        try{
            return indexService.getAllInfo();
        }catch (Exception e){
            e.printStackTrace();
            return asMap(
                    asTuple2("code",-1),
                    asTuple2("msg","Server Error")
            );
        }
    }


}
